﻿/**
*┌──────────────────────────────────────────────────────────────┐
*│　描    述：Shop_Bills                                                    
*│　作    者：NetCoreCMS                                            
*│　版    本：1.0    模板代码自动生成                                                
*│　创建时间：2019-12-25 10:52:46                             
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│　命名空间： NetCoreCMS.Services                                  
*│　类    名： Shop_BillsService                                    
*└──────────────────────────────────────────────────────────────┘
*/
using NetCoreCMS.Common;
using NetCoreCMS.IRepository;
using NetCoreCMS.IServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetCoreCMS.Services
{
    public class Shop_BillsService : IShop_BillsService
    {
        private readonly IShop_BillsRepository _repository;
        private readonly IShopRepository _shop;

        public Shop_BillsService(IShop_BillsRepository repository, IShopRepository shop)
        {
            _repository = repository;
            _shop = shop;
        }
        public List<Models.Shop_Bills> GetList(int pageNumber, int rowsPerPage, string conditions, string orderby, object parameters = null)
        {
            return _repository.GetListPaged(pageNumber, rowsPerPage, conditions, orderby, parameters).ToList();
        }
        public int RecordCount(string conditions, object parameters = null)
        {
            return _repository.RecordCount(conditions, parameters);
        }
        public bool Delete(int id)
        {
            return _repository.Delete(id) > 0;
        }

        public bool Add(int user_id, int shop_id, decimal point, int leixing)
        {
            Models.Shop_Bills bill = new Models.Shop_Bills();
            bill.point = point;
            bill.remark = "P" + Utils.GetOrderNumber(); 
            bill.shop_id = shop_id;
            bill.status = leixing;
            bill.user_id = user_id;
            if (_shop.Pay(user_id, shop_id, point, leixing))
            {
                return _repository.Insert(bill) > 0;
            }
            return false;
        }
    }
}